"""
@Author: li
@Email: lijianqiao2906@live.com
@FileName: role.py
@DateTime: 2025/07/06
@Docs: 角色相关的 Pydantic Schema
"""

from pydantic import Field

from app.schemas.base import BaseRequest
from app.schemas.permission import PermissionRead


class RoleBase(BaseRequest):
    """角色基础 Schema"""

    name: str = Field(max_length=50, description="角色名称")
    code: str = Field(max_length=50, description="角色编码")
    sort_order: int = Field(default=0, description="排序")
    description: str | None = Field(default=None, description="描述")


class RoleCreate(RoleBase):
    """创建角色 Schema"""

    permission_ids: list[int] = Field(default_factory=list, description="关联的权限ID列表")


class RoleUpdate(BaseRequest):
    """更新角色 Schema (所有字段可选)"""

    name: str | None = Field(default=None, max_length=50, description="角色名称")
    code: str | None = Field(default=None, max_length=50, description="角色编码")
    sort_order: int | None = Field(default=None, description="排序")
    description: str | None = Field(default=None, description="描述")
    permission_ids: list[int] | None = Field(default=None, description="关联的权限ID列表")


class RoleRead(RoleBase):
    """读取角色 Schema"""

    id: int = Field(description="角色ID")
    permissions: list[PermissionRead] = Field(default_factory=list, description="关联的权限列表")

    class Config:
        from_attributes = True
